<?php include('scripts.php'); ?>

<script type="text/javascript">
$(function() {
    $("#transferForm").validate({
        messages : {
            transactionPassword: {
                remote: "Security Password is not valid."
            }
        },
        rules : {
            "sponsorId" : {
                required: true
                //, minlength : 8
            },
            "ecashAmount" : {
                required : true
            },
            "transactionPassword" : {
                required : true,
                remote: "/member/verifyTransactionPassword"
            }
        },
        submitHandler: function(form) {
            waiting();
            var amount = $('#ecashAmount').autoNumericGet();
            var ecashBalance = $('#ecashBalance').autoNumericGet();

            if (parseFloat(ecashBalance) < (parseFloat(amount) + parseFloat($("#processFee").val()))) {
                alert("<?php echo __("In-sufficient e-Cash")?>");
                return false;
            }

            $("#ecashAmount").val(amount);
            form.submit();
        }
    });

    $("#sponsorId").change(function(){
        if ($.trim($('#sponsorId').val()) != "") {
            verifySponsorId();
        }
    });

    $('#ecashAmount').autoNumeric({
        mDec: 2
    });
});

function verifySponsorId() {
    waiting();
    $.ajax({
        type : 'POST',
        url : "/member/verifySponsorId",
        dataType : 'json',
        cache: false,
        data: {
            sponsorId : $('#sponsorId').val()
        },
            success : function(data) {
                if (data == null || data == "") {
                    alert("Invalid sponsor ID");
                    $('#sponsorId').focus();
                    $("#sponsorName").html("");
                } else {
                    $.unblockUI();
                    $("#sponsorName").html(data.nickname);
                }
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                alert("Your login attempt was not successful. Please try again.");
            }
        });
}
</script>

<form action="/member/transferEcash" id="transferForm" method="post">
<input type="hidden" id="processFee" value="<?php echo $processFee?>">
<div style="padding: 10px; top: 30px; width: 98%">
<div class="portlet">
    <div class="portlet-header"><?php echo __('e-Cash Transfer') ?></div>
    <div class="portlet-content">

<?php if ($sf_flash->has('successMsg')): ?>
<div class="ui-widget">
    <div style="margin-top: 10px; margin-bottom: 10px; padding: 0 .7em;"
         class="ui-state-highlight ui-corner-all">
        <p style="margin: 10px"><span style="float: left; margin-right: .3em;"
                 class="ui-icon ui-icon-info"></span>
            <strong><?php echo $sf_flash->get('successMsg') ?></strong></p>
    </div>
</div>
<?php endif; ?>
<?php if ($sf_flash->has('errorMsg')): ?>
<div class="ui-widget">
    <div style="margin-top: 10px; margin-bottom: 10px; padding: 0 .7em;"
         class="ui-state-error ui-corner-all">
        <p style="margin: 10px"><span style="float: left; margin-right: .3em;"
                 class="ui-icon ui-icon-alert"></span>
            <strong><?php echo $sf_flash->get('errorMsg') ?></strong></p>
    </div>
</div>
<?php endif; ?>
<br>
<table cellpadding="0" cellspacing="5" align="center" border="0">
    <tr>
        <td width="160px">
			<strong><?php echo __('Shareholder ID'); ?></strong>
		</td>
        <td width="1px">:</td>
		<td>
			<input name="sponsorId" type="text" id="sponsorId" tabindex="1" />
		</td>
    </tr>
    <tr>
        <td>
			<strong><?php echo __('Shareholder Name'); ?></strong>
		</td>
        <td>:</td>
		<td>
			<strong><span id="sponsorName"></span></strong>
		</td>
    </tr>
    <tr>
        <td>
			<strong><?php echo __('e-Cash Balance'); ?></strong>
		</td>
        <td>:</td>
		<td>
			<input name="ecashBalance" id="ecashBalance" tabindex="2" disabled="disabled" value="<?php echo number_format($ledgerAccountBalance,2); ?>"/>
		</td>
    </tr>
    <tr>
        <td>
			<strong><?php echo __('Transfer e-Cash Amount'); ?></strong>
		</td>
        <td>:</td>
		<td>
			<input name="ecashAmount" id="ecashAmount" tabindex="3" />
		</td>
    </tr>
    <tr>
        <td>
			<strong><?php echo __('Security Password'); ?></strong>
		</td>
        <td>:</td>
		<td>
			<input name="transactionPassword" type="password" id="transactionPassword" tabindex="4" />
		</td>
    </tr>    
    <tr>
    	<td colspan=3><font color="#dc143c"> <?php
            if ($processFee != 0)
                echo __('every transfer action need to pay USD%1%.00 processing fees', array('%1%' => $processFee));
        ?></font></td>
    </tr>
    <tr>
        <td colspan='3' align='center'>
			<input type="submit" name="Button1" value="<?php echo __('Submit') ?>" language="javascript" id="btnTransfer" tabindex="5"/>
		</td>
    </tr>
</table>
    </div>
</div>
</div>
</form>